package cn.factorybox.item.controller;

import cn.factorybox.common.entity.Result;
import cn.factorybox.item.service.DeviceDataAppService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-03-25 17:20
 */

@RestController
@RequestMapping("app")
public class DeviceDataAppController {

    @Autowired
    private DeviceDataAppService deviceDataAppService;

    @ApiOperation(value = "获取当前天、前七天的历史数据",notes = "获取当前天、前七天的历史数据")
    @GetMapping("devicedata")
    public Result getAppData(@RequestParam("fSerialNumber") String fSerialNumber) throws Exception {
        Map<String,Object> map = new HashMap<>();
        Map<String,Object> map1 = deviceDataAppService.getAppData(fSerialNumber).get();
        Map<String,Object> map2 = deviceDataAppService.getDayHistory(fSerialNumber).get();
        Map<String,Object> map3 = deviceDataAppService.getWeekHistory(fSerialNumber).get();
        map.putAll(map1);
        map.putAll(map2);
        map.putAll(map3);
        return Result.ok(map);
    }

}
